﻿using System;
using System.Collections.Generic;
using System.Text;
using Gmmy.Utility.Enums;
using Newtonsoft.Json;

namespace Gmmy.Utility
{
    [Serializable]
    public class CustomApiResult
    {
        public CustomApiResultCode code { get; set; }
        public string message { get; set; }
        public dynamic data { get; set; }

        public static CustomApiResult GetResult(object json)
        {
            var result=new CustomApiResult();
            if (json==null)
            {
                return null;
            }
            try
            {
                result =JsonConvert.DeserializeObject<CustomApiResult>(json.ToString());
            }
            catch (Exception e)
            {
                result.message = CustomApiResultCode.MessageFormatErr.GetLocalizedDescription();
                result.code = CustomApiResultCode.MessageFormatErr;
            }
            return result;
        }
    }
}
